//
//  CustomerInfoOneVC.m
//  AI
//
//  Created by zjhc on 2018/2/13.
//  Copyright © 2018年 zjhc. All rights reserved.
//

#import "CustomerInfoOneVC.h"
#import "TodayCustomerCollectionViewCell.h"
#import "TodayCustomerModel.h"
#import "CustomerInfoTwoVC.h"

@interface CustomerInfoOneVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property  (strong,nonatomic) NSMutableArray *dataArray;

@end

@implementation CustomerInfoOneVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.dataArray = [[NSMutableArray alloc]init];

    [self getRequestData];
    self.title = @"客户信息";
    // Do any additional setup after loading the view.
}

-(void)getRequestData{
    for (int i = 0; i < 4; i ++ ) {
        TodayCustomerModel *model  = [[TodayCustomerModel alloc]init];
        model.iconStr = @"http://img2.woyaogexing.com/2017/12/26/64c1913b6c511185!200x200.jpg";
        model.timeRange = @"01月10日  11:30-12:00";
        model.receptionStatus = arc4random()%2;
        model.receptioner = [NSString stringWithFormat:@"receptioner%d",i];
        [self.dataArray addObject:model];
    }
    [self.collectionView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:( NSIndexPath *)indexPath {
    TodayCustomerCollectionViewCell *cell
    =[collectionView dequeueReusableCellWithReuseIdentifier:@"TodayCustomerCollectionViewCell" forIndexPath:indexPath];
    
    TodayCustomerModel * model = [self.dataArray objectAtIndex:indexPath.row];
    [cell.avatar  setBackgroundImage:[UIImage imageNamed:@"头像测试"] forState:UIControlStateNormal];
    cell.avatar.layer.cornerRadius = cell.avatar.frame.size.width/2;
    cell.avatar.layer.masksToBounds = YES;
    cell.name.text = @"王璐丹";
    
        return cell;
}

- (CGSize) collectionView:(UICollectionView *)collectionView
                   layout:(UICollectionViewLayout *)collectionViewLayout
   sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(50.0f, 73.0f);
}

//- (CGFloat) collectionView:(UICollectionView *)collectionView
//                    layout:(UICollectionViewLayout *)collectionViewLayout
//minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
//{
//    return 25.0f;
//}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row ==0) {
        [self performSegueWithIdentifier:@"CustomerInfoThreeVCSegue" sender:self];
    } else {
        [self performSegueWithIdentifier:@"customerInfoTwo" sender:self];
    }
}


- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                        layout:(UICollectionViewLayout *)collectionViewLayout
        insetForSectionAtIndex:(NSInteger)section{


    return UIEdgeInsetsMake(0, 12.5, 0,12.5);
}

- (IBAction)refreshAvatarList:(id)sender {
    [self.collectionView reloadData];
}

-(void)viewWillAppear:(BOOL)animated {
    self.tabBarController.tabBar.hidden = YES;
}

@end
